package com.lee.controller;

import com.lee.entity.Person;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.Date;

/**
 * Created by lee on 2017/3/14.
 */
@Controller
@RequestMapping("/json")
public class JsonController {

    @ResponseBody
    @RequestMapping("/user")
    public Person get() {
        Person u = new Person();
        u.setId(625);
        u.setName("dss收电费收费");
        u.setBirth(new Date());
        return u;
    }

    // 处理局部异常（Controller内）
    @ExceptionHandler
    public ModelAndView exceptionHandler(Exception ex) {
        ModelAndView mv = new ModelAndView("error");
        mv.addObject("exception", ex);
        System.out.println("in testExceptionHandler");
        return mv;
    }

    @RequestMapping("/hello")
    public String error() {
        int i = 5 / 0;
        return "hello";
    }
}
